define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'yikatong/ysskmj/index',
                    add_url: 'yikatong/ysskmj/add',
                    edit_url: 'yikatong/ysskmj/edit',
                    del_url: 'yikatong/ysskmj/del',
                    multi_url: 'yikatong/ysskmj/multi',
                    table: 'yikatong_ysskmj',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'empno', title: __('Empno')},
                        {field: 'cardno', title: __('Cardno')},
                        {field: 'cardtype', title: __('Cardtype'), formatter: function(value){ var statuses = {0: '卡号', 1:'序列号', 2:'变种号'}; return statuses[value]; }},
                        {field: 'gatime', title: __('Gatime')},
                        {field: 'sktime', title: __('Sktime')},
                        {field: 'jh', title: __('Jh')},
                        {field: 'doorno', title: __('Doorno')},
                        {field: 'areano', title: __('Areano')},
                        {field: 'teamsyscode', title: __('Teamsyscode')},
                        {field: 'teamname', title: __('Teamname')},
                        {field: 'rdh', title: __('Rdh')},
                        {field: 'rdjczt', title: __('Rdjczt'), formatter: function(value){ var statuses = {0: '无', 1:'进', 2:'出'}; return statuses[value]; }},
                        {field: 'rdskbusi', title: __('Rdskbusi')},
                        {field: 'txtype', title: __('Txtype'), formatter: function(value){ var statuses = {"-1": '未注册', 3:'刷卡', 4:'刷卡/密码', 5: '编号/密码', 13: '未知'}; return statuses[value]; }},
                        {field: 'pdjg', title: __('Pdjg'), formatter: function(value){ var statuses = {0: '未处理', 1:'无效', 2:'正常', 3: '迟到', 4: '早退', 5: '代打卡'}; return statuses[value]; }},
                        // {field: 'photo', title: __('Photo')},
                        // {field: 'addr', title: __('Addr')},
                        // {field: 'reason', title: __('Reason')},
                        // {field: 'xgevent', title: __('Xgevent')},
                        // {field: 'edittag', title: __('Edittag')},
                        // {field: 'tagpf10', title: __('Tagpf10')},
                        // {field: 'tagpf11', title: __('Tagpf11')},
                        // {field: 'row_number', title: __('Row_number')},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});